package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.activity.peakseacraft.PeakSeacraftCrossUnionData;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eUnionPosition;
import com.yanqu.road.entity.rank.cross.CrossUserRank;
import com.yanqu.road.logic.bussiness.activity.PeakSeacraftBusiness;
import com.yanqu.road.logic.cross.CrossActivityRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.pb.crossunion.activity.CrossUnionActivityRankDataProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;

import java.util.Map;

/**
 * @Description
 */
public class PeakSeacraftActivityRank extends BaseCrossRank {

    public PeakSeacraftActivityRank(int activityId) {
        super(activityId);
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        AutoSendRewardProto.CrossUserRankMsg.Builder msg = AutoSendRewardProto.CrossUserRankMsg.newBuilder();
        msg.setActivityId(activityId);
        //改商会分组活动后,这里不用了
//        Map<Integer, CrossActivityRankListModel> modelMap = ActivityRankMgr.getCrossActivityNewRankListModelMap(activityId);
//        if (modelMap != null) {
//            for (Map.Entry<Integer, CrossActivityRankListModel> entry : modelMap.entrySet()) {
//                CrossActivityRankListModel rankListModel = entry.getValue();
//                int conditionType = rankListModel.getConditionType();
//                if (conditionType != eGamePlayerEventType.PeakSeacraftUserScoreRank.getValue()) {
//                    continue;
//                }
//                int rank = 0;
//                for (CrossUserRank rankData : rankListModel.getRankList()) {
//                    long userId = rankData.getUserId();
//                    rank++;
//                    addUserRankData(msg, conditionType, userId, rank);
//                }
//            }
//        }
        return msg;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        // 联盟排行
        Map<String, PeakSeacraftCrossUnionData> map = PeakSeacraftBusiness.getAllPeakSeacraftCrossUnionDataMap(activityId);
        for (PeakSeacraftCrossUnionData item : map.values()){
            if(item.getUnionBaseInfo() != null){
                AutoSendRewardProto.UnionRankMsg.Builder builder = AutoSendRewardProto.UnionRankMsg.newBuilder();
                builder.setConditionType(eGamePlayerEventType.PeakSeacraftUnionRank.getValue());
                builder.setUnionId(item.getUnionId());
                builder.setRank(item.getRank());
                item.getMemberMap().forEach((memberId, post) -> {
                    builder.addPosList(CrossUnionActivityRankDataProto.CrossUnionMemberPosDataMsg.newBuilder().setUserId(memberId).setPos(post));
                });
                msg.addData(builder);
            }
        }
        return msg;
    }
}
